package com.lhkj.ct.admin.modules.warning.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.annntation.PreventDuplicateSubmit;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.modules.warning.model.entity.TblPsyConsRecord;
import com.lhkj.ct.meta.modules.warning.model.vo.PsyConsRecordVo;
import com.lhkj.ct.meta.modules.warning.service.PsyConsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 心理咨询记录 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2023-10-30
 */
@RestController
@RequestMapping("api/plat/warning/cons/records")
@Validated
@Api(tags = "3.2心理咨询")
public class PsyConsRecordsController {

    @Resource
    private PsyConsRecordService psyConsRecordService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页查询")
    @GetMapping("list")
    public ActionResult<IPage<TblPsyConsRecord>> list(TblPsyConsRecord records, PageQuery pageQuery) {
        return ActionResult.success(psyConsRecordService.selectPages(records, pageQuery));
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "用户历史记录")
    @GetMapping("{patId}/histories")
    public ActionResult<IPage<TblPsyConsRecord>> histories(PageQuery pageQuery, @PathVariable String patId) {
        return ActionResult.success(psyConsRecordService.selectHistoriesByUser(patId, pageQuery));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "表单数据")
    @GetMapping("{id}/get")
    public ActionResult<TblPsyConsRecord> get(@PathVariable String id) {
        return ActionResult.success(psyConsRecordService.getById(id));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查看")
    @GetMapping("{id}/view")
    public ActionResult<PsyConsRecordVo> view(@PathVariable String id) {
        return ActionResult.success(psyConsRecordService.get(id));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增")
    @PreventDuplicateSubmit
    @PostMapping(value = "insert")
    @Log(title = "心理治疗", actionType = ActionType.INSERT)
    public ActionResult<String> insert(@Validated @RequestBody TblPsyConsRecord entity) {
        psyConsRecordService.insert(entity);
        return ActionResult.success("保存成功", entity.getId());
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改")
    @PreventDuplicateSubmit
    @PutMapping(value = "update")
    @Log(title = "心理治疗", actionType = ActionType.UPDATE)
    public ActionResult<String> update(@Validated @RequestBody TblPsyConsRecord entity) {
        psyConsRecordService.updateById(entity);
        return ActionResult.success("保存成功", entity.getId());
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除", notes = "支持批量")
    @DeleteMapping("delete")
    @Log(title = "心理治疗", actionType = ActionType.DELETE)
    public ActionResult<Void> delete(@RequestBody @NotEmpty(message = "请选择需要删除的记录") List<String> ids) {
        int count = psyConsRecordService.removeByIds(ids);
        return ActionResult.success(String.format("操作成功，共删除%d条记录", count));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "导出pdf")
    @PostMapping(value = "{rId}/exportPdf")
    @Log(title = "心理治疗", actionType = ActionType.EXPORT)
    public void exportPdf(@PathVariable String rId) {
        psyConsRecordService.exportPdf(rId);
    }
}
